package com.sell.sell.controller;

import com.sell.sell.enums.ResultEnum;
import com.sell.sell.exception.SellException;
import com.sell.sell.form.OrderForm;
import com.sell.sell.util.ResultVOUtil;
import com.sell.sell.vo.OrderVO;
import com.sell.sell.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 描述:
 * 订单处理控制器
 *
 * @author hzp
 * @create 2018-10-08 17:52
 */
@RestController
@RequestMapping("/buyer/order")
@Slf4j
public class BuyerOrderController {

    /**
     * 创建订单
     * @return
     */
    @PostMapping("/create")
    public ResultVO create(@Valid OrderForm orderForm, BindingResult bindingResult){

        OrderVO orderVO=new OrderVO();
        //获取商品
        if(bindingResult.hasErrors()){  //form表单验证不通过
            log.error("创建订单失败原因："+bindingResult.getFieldError().getDefaultMessage(),orderForm);
//            ResultVO<OrderVO> resultVO=new ResultVO<>();
//            return ResultVOUtil.error(bindingResult.getFieldError().getDefaultMessage());
            throw new SellException(bindingResult.getFieldError().getDefaultMessage(),ResultEnum.PARAM_ERROR.getCode());
        }
        //相应得json数据转为可以下单得商品数据

        //进行下单操作

        return null;
    }

}
